package com.ttuproject.ttu.controller;

import com.ttuproject.ttu.advice.ResponseEnvelope;
import com.ttuproject.ttu.exception.Advice;
import com.ttuproject.ttu.service.LinkageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @ClassName LinkageController
 * @Description 包含各类联动方法的返回值
 * @Author 15032
 * @Date 2021/12/3 10:39
 */
@Api(value = "台区联动接口", tags = "台区联动接口", description = "台区联动接口")
@RestController
public class LinkageController {

    @Autowired
    LinkageService linkageService;

    /**
     * @explain: 台区联动接口
     * @author: cw
     * @date: 2021/12/3
     */

    @GetMapping("/linkage/1")
    //@RequestMapping("/linkage/1")
    public ResponseEntity<ResponseEnvelope<Set<String>>> linkage1() {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.LINKAGE_SUCCESS_1, linkageService.linkage1()));
    }

   // @RequestMapping("/linkage/2")
    @GetMapping("/linkage/2")
    public ResponseEntity<ResponseEnvelope<Set<String>>> linkage2(@RequestParam("linkage1") String linkage1) {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.LINKAGE_SUCCESS_2, linkageService.linkage2(linkage1)));
    }

   // @RequestMapping("/linkage/3")
    @GetMapping("/linkage/3")
    public ResponseEntity<ResponseEnvelope<Set<String>>> linkage3(@RequestParam("linkage1") String linkage1, @RequestParam("linkage2") String linkage2) {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.LINKAGE_SUCCESS_3, linkageService.linkage3(linkage1, linkage2)));
    }

   // @RequestMapping("/GPS")
    @GetMapping("/GPS")
    public ResponseEntity<ResponseEnvelope<String>> queryGPS(@RequestParam("linkage1") String linkage1, @RequestParam("linkage2") String linkage2, @RequestParam("linkage3") String linkage3) {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.QUERY_GPS_SUCCESS, linkageService.queryGPS(linkage1, linkage2, linkage3)));
    }


    /**
     * @explain: 故障检测及原因代码
     * @author: cw
     * @date: 2021/12/3
     */
   // @RequestMapping("/fault")
    @GetMapping("/fault")
    public ResponseEntity<ResponseEnvelope<Set<String>>> selectFaultcode() {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.FAULT_CODE_SUCCESS, linkageService.selectFaultcode()));
    }

    //@RequestMapping("/failure_cause")
    @GetMapping("/failure_cause")
    public ResponseEntity<ResponseEnvelope<String>> selectFailurecause(@RequestParam("faultcode") String faultcode) {
        return ResponseEntity.ok(new ResponseEnvelope<>(Advice.FAILURE_CAUSE_SUCCESS, linkageService.selectFailurecause(faultcode)));
    }
}
